package com.cyf.service.impl;

import com.cyf.db.bean.ApiUser;
import com.cyf.db.mapper.ApiUserMapper;
import com.cyf.db.mapper.ApiUserParkingMapper;
import com.cyf.pay.alipay.bean.IsvAppAuthToken;
import com.cyf.service.ApiUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zym
 * @date 2020/6/23 7:13
 */
@Service
public class ApiUserServiceImpl implements ApiUserService {

    @Autowired
    private ApiUserParkingMapper apiUserParkingMapper;
    @Autowired
    private ApiUserMapper apiUserMapper;

    @Override
    public ApiUser getLastApiUserNoCyfByParkingId(Integer parkingId, boolean aliPayWay) {
        ApiUser apiUser = null;
        List<Integer> apiUserIdList = apiUserParkingMapper.listApiUserIdNoCyfForIsvpayByParkingId(parkingId);
        if (apiUserIdList != null) {
            for (int i = apiUserIdList.size() - 1; i >= 0; i--) {
                Integer apiUserId = apiUserIdList.get(i);
                if (apiUserId != null) {
                    apiUser = apiUserMapper.getById(apiUserId);
                    if (apiUser != null) {
                        // 微信支付
                        if (StringUtils.isNotEmpty(apiUser.getServiceSubMchId())) {
                            return apiUser;
                        }
                        break;
                    }
                }
            }
        }
        return apiUser;
    }
}
